package org.example;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;

/**
 * 数据格式化工具
 */
public class DbFormatUtils {

    public static void main(String[] args) throws Exception {
        StringBuilder result = new StringBuilder();
        String fileStr = FileUtils.readFileToString(new File("C:\\Users\\ThinkPad\\Desktop\\核查结果迁移表\\dump0-100.txt"));
        String[] lineArr = fileStr.split("\r\n");
        StringBuilder tmpBuilder = new StringBuilder();
        for (int i = 0; i < lineArr.length; i++) {
            String line = lineArr[i];
            if (i == lineArr.length - 1 && (i + 1) % 50 != 0) {
                line = "\"" + line + "\"";
                String tmpBuilderStr = tmpBuilder.toString();
                result.append("util.dumpTables(\"ncc_flow\", [");
                result.append(tmpBuilderStr + line);
                result.append("], \"step_" + (((i + 1) / 50) + 1) + "\")");
                result.append("\n");
            }
            if (StringUtils.isBlank(line)) {
                continue;
            }
            if ((i + 1) % 50 == 0) {
                line = "\"" + line + "\"";
                String tmpBuilderStr = tmpBuilder.toString();
                result.append("util.dumpTables(\"ncc_flow\", [");
                result.append(tmpBuilderStr + line);
                result.append("], \"step_" + ((i + 1) / 50) + "\")");
                result.append("\n");
                tmpBuilder = new StringBuilder();
            } else {
                line = "\"" + line + "\",";
                tmpBuilder.append(line);
            }
        }
        FileUtils.writeStringToFile(new File("C:\\Users\\ThinkPad\\Desktop\\核查结果迁移表\\dump1.txt"), result.toString());
    }

}
